package com.ysd.lis.service.qi.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.qi.QiIndexCond;
import com.ysd.lis.mapper.qi.QiIndexCondMapper;
import com.ysd.lis.service.qi.QiIndexCondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 指标项目条件表 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-02-05
 */
@Service
public class QiIndexCondServiceImpl extends ServiceImpl<QiIndexCondMapper, QiIndexCond> implements QiIndexCondService {

    @Autowired
    QiIndexCondMapper qiIndexCondMapper;

    @Override
    public Result getIndexConditionList(String indexItemId) {
        LambdaQueryWrapper<QiIndexCond> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(QiIndexCond::getDelFlag, 0)
                .eq(QiIndexCond::getItemId, indexItemId);
        List<QiIndexCond> QiIndexConds = qiIndexCondMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功", QiIndexConds);
    }

    @Override
    public Result addQiIndexCondition(List<QiIndexCond> qiIndexConds) {
        boolean save = this.saveBatch(qiIndexConds);
        if (save) {
            return Result.succ(1, "添加成功", null);
        } else {
            return Result.fail("添加失败");
        }
    }

    @Override
    public Result updateQiIndexCondition(List<QiIndexCond> qiIndexConds) {
        boolean save = this.updateBatchById(qiIndexConds);
        if (save) {
            return Result.succ(1, "编辑成功", null);
        } else {
            return Result.fail("编辑失败");
        }
    }

    @Override
    public Result deleteQiIndexCondition(QiIndexCond qiIndexCond) {
        boolean delete = this.removeById(qiIndexCond.getId());
        if (delete) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail("删除失败");
        }
    }
}
